﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
    <head>
        <title>Success</title>

        <script type="text/javascript"  language="javascript"  src="https://api.conduit.com/BrowserCompApi.js"></script>
        <script type="text/javascript">
//            window.onload = function ()
//            {
//                // there is no access in ie
//                try
//                {
//                    if (opener)
//                        opener.setAccessToken("@ViewBag.Token");
//                }
//                catch (e) // if opener cannot be accessed but this window can be accessed
//                {
//                    window.res = "@ViewBag.Token";
//                    window.finished = true;
//                }

//                window.close();
//            }

//            window.onload = function ()
//            {
//                window.res = "@ViewBag.Token";
//                window.finished = true;
            //            }

            window.onload = function () {
                try {// chrome
                    if (opener && opener.setAccessToken) {
                        opener.setAccessToken("@ViewBag.Token");
                        window.close();
                        return;
                    }
                    else {
                        setAccessToken("@ViewBag.Token");
                    }
                }
                catch (e) {
                }
                // ie ff
                setAccessToken("@ViewBag.Token");
            }


            function Set_Cookie(name, value, expires, path, domain, secure) {
                // set time, it's in milliseconds
                var today = new Date();
                today.setTime(today.getTime());

                /*
                if the expires variable is set, make the correct
                expires time, the current script below will set
                it for x number of days, to make it for hours,
                delete * 24, for minutes, delete * 60 * 24
                */
                if (expires) {
                    expires = expires * 1000 * 60 * 60 * 24;
                }
                var expires_date = new Date(today.getTime() + (expires));

                document.cookie = name + "=" + escape(value) +
                ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
                ((path) ? ";path=" + path : "") +
                ((domain) ? ";domain=" + domain : "") +
                ((secure) ? ";secure" : "");
            }


            function setAccessToken(token) {
                debugger;
                try {
                    if (typeof GetInfo != "undefined" && GetInfo()) {
                        StoreGlobalKey("accessToken", token);
                        }
                    else
                    {
                        Set_Cookie("access_token", token, true, '/', false, true);
                    }

                }
                catch (er) { 
                
                Set_Cookie ("access_token",token,true,'/',false,true);
                }
                goToNext();
            }

            function goToNext()
            {
                var goto = '@ViewBag.Goto';
                if (goto && goto.length > 4)
                    window.location.href = goto;
                else window.location = '/tasks/index';
            }
        </script>
    </head>
    <body>
    </body>

</html>

